package com.example.a514;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import receiver.OrderedAReceiver;
import receiver.OrderedBReceiver;

public class BroadOrderActivity extends AppCompatActivity implements View.OnClickListener {
    public final static String ORDERb = "mmmmmmmmmmmmmmmmmmmmmm";
    private OrderedAReceiver receiverA;
    private OrderedBReceiver receiverB;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_broad_order);

        findViewById(R.id.btn_send).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(ORDERb);
        sendOrderedBroadcast(intent,null);
    }

    @Override
    protected void onStart() {
        super.onStart();
        receiverA= new OrderedAReceiver() ;
        IntentFilter filterA = new IntentFilter(BroadOrderActivity.ORDERb);
        filterA.setPriority(8);
        registerReceiver(receiverA,filterA);


        receiverB = new OrderedBReceiver();
        IntentFilter filterB = new IntentFilter(BroadOrderActivity.ORDERb);
        filterB.setPriority(10);
        registerReceiver(receiverB,filterB);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(receiverA);
        unregisterReceiver(receiverB);
    }
}